/*
 *  $Id: SpiderQueen.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Darkness.Creatures {
    public class SpiderQueen: DemonCreatureCard {
        public SpiderQueen(): base("001_d_c_spider_queen") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Darkness;
            Value = 100;
            Damage = 4;
            Health = 6;
            AddManaCost(ElementType.Darkness, 6);
            PactValue = 3;
        }
        public override void SetNaturalAffects(ICollector<Affect> affects) {
            affects.Add<Affects.Fearless>();
            affects.Add<Affects.NonBlocked>();
        }
        public override void SetAbilities(ICollector<AbilityCard> abilities) {
            abilities.Add<Abilities.SpidersCall>();
        }

        public override void ExecutePact(Player owner) {
            owner.AddAffect<DemonicWeb>();
        }

        private class DemonicWeb: SpellAffect<SpiderQueen> {
            public DemonicWeb(): base(true) {
                DefaultName = true;
                DefaultDescription = true;
            }

            public override void SetAffect() {
                base.SetAffect();
                GlobalSummary.OnAttackTry += DoAttack;
                EnemySummary.OnAttackTry += DoAttack;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                GlobalSummary.OnAttackTry -= DoAttack;
                EnemySummary.OnAttackTry -= DoAttack;
            }

            private void DoAttack(Creature attacker, ref bool canAttack) {
                DoAttack(attacker, true);
                DoAttack(attacker.NeighbourLeft, false);
                DoAttack(attacker.NeighbourRight, false);
            }
            private void DoAttack(Creature attacker, bool onlyAffect) {
                if (attacker == null) return;
                if (!onlyAffect && attacker.CanAttack) {
                    if (attacker.Disabled) attacker.DamageDirectBy(NewDamage(DamageType.MagicAttack, 1), true);
                    attacker.State = CreatureState.Offence;
                }
                attacker.AddAffect(new TimeAffect(1, new Affects.Berserk()));
            }
        }
    }
}
